﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HousingInfo.Library;

namespace WebHousingInfo.Controls
{
    public partial class Timkiemtrentrangchu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getArea();
                gethousingType();
                getAreaDetailByAreaID(drlarea.SelectedValue);
            }
        }


        private void gethousingType()
        {
            HousingTypeInfo housingType = HousingTypeInfo.GetHousingTypeInfo();
            drlhousetype.DataSource = housingType;
            drlhousetype.DataBind();
            drlhousetype.Items.Insert(0, "Tất cả");
            drlhousetype.SelectedIndex = 0;
        }
        protected void drlarea_SelectedIndexChanged(object sender, EventArgs e)
        {
            areaChanged();
        }

        private void getArea()
        {
            var area = AreaInfo.GetAreaInfo();
            drlarea.DataSource = area;
            drlarea.DataBind();
            drlarea.Items.Insert(0, "Tất cả");
            drlarea.SelectedIndex = 0;
        }
        private void areaChanged()
        {
            if (drlarea.SelectedItem.Text != "Tất cả")
            {
                var areaID = drlarea.SelectedValue;
                getAreaDetailByAreaID(areaID);
            }
            else
            {
                drlareadetail.Items.Clear();
                drlareadetail.Items.Add("Tất cả");
            }
        }
        private void getAreaDetailByAreaID(string areaID)
        {
            if (areaID != "Tất cả")
            {
                var areaDetail = AreaBO.GetAreaBO(int.Parse(areaID)).AreaDetailBOList;
                drlareadetail.DataSource = areaDetail;
                drlareadetail.DataBind();
                drlareadetail.Items.Insert(0, "Tất cả");

            }
            else
            {
                drlareadetail.Items.Clear();
                drlareadetail.Items.Add("Tất cả");
            }
        }

        protected void drlprice_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}